export const layoutForce = { label: '力学布局', layoutName: 'force', layoutClassName: 'seeks-layout-force' };
export const layoutCenter = { label: '中心布局', layoutName: 'center', layoutClassName: 'seeks-layout-center' };
export const layoutTreeH = { label: '树状布局', layoutName: 'tree', layoutClassName: 'seeks-layout-center', defaultJunctionPoint: 'border', defaultNodeShape:  0, defaultLineShape:  1, min_per_width: 40, max_per_width: 70, min_per_height: 200 };
export const layoutTreeV = { label: '树状布局', layoutName: 'tree', layoutClassName: 'seeks-layout-center', defaultJunctionPoint: 'border', defaultNodeShape:  0, defaultLineShape: 5, from: 'left', max_per_width: 300, min_per_height: 40 };

export const graphLayouts = ['力学布局', '中心布局', '树状布局'];
export const treeLayouts = ['横向树状图谱', '纵向树状图谱'];

/**
 * 获取图表配置
 * @param {*} layout 布局方式
 * @returns 
 */
export function getGraphOptions(layout) {
  const graphOptions = {
    debug: false,
    defaultNodeBorderWidth: 0,
    allowShowMiniToolBar: true,
    allowSwitchLineShape: true,
    allowSwitchJunctionPoint: true,
    defaultLineShape: 1,
    disableNodeclickEffect: true,
    layout: layout || layoutForce,
    defaultJunctionPoint: 'border'
  }
  return graphOptions;
}

/**
 * 获取节点图标
 * @param {*} node 节点对象
 * @param {*} showIcon 是否显示图标，默认 true，若 node.data.icon 为空，则显示相应的本地默认图标
 * @returns 
 */
export function getNodeIcon(node, showIcon = true) {
  if (node.data.icon && showIcon) {
    return node.data.icon;
  }

  const sexType = node.data.sexType;
  if (sexType === "男") return require("../assets/icon-node-male.png");
  if (sexType === "女") return require("../assets/icon-node-female.png");

  const dataType = node.data.dataType;
  if (dataType === "car") return require("../assets/icon-node-car.png");
  if (dataType === "phone") return require("../assets/icon-node-phone.png");

  return null;
}

/**
 * 获取节点背景图片
 * @param {*} node 节点对象
 * @returns 
 */
export function getNodeBackground(node) {
  // 预设了 7 个特殊标签，可供特殊节点显示标记使用
  const tags = ["red", "orange", "yellow", "green", "cyan", "blue", "purple"];
  const tag = node.data.backgroundTag;
  if (!tag || !tags.includes(tag)) return null;

  const backgroundImag = require(`../assets/icon-bg-${tag}.png`);
  return backgroundImag;
}